package com.appkubes.mall.admin.application.system.kd.controller;


import com.appkubes.common.Response;
import com.appkubes.mall.admin.application.base.BaseController;
import com.appkubes.mall.admin.application.system.kd.entity.vo.KdCompanyAddVO;
import com.appkubes.mall.admin.application.system.kd.service.KdCompanyService;
import com.appkubes.mall.admin.utils.PageUtil;
import com.appkubes.mall.core.entity.MallKdCompany;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("快递公司模块")
@RestController
@RequestMapping("/sass_admin/KdCompany")
public class KdCompanyController extends BaseController {


    @Autowired
    KdCompanyService kdCompanyService;

    @ApiOperation(value = "快递列表")
    @PostMapping("/getList")
    public Response getList() {
        PageInfo<MallKdCompany> pageinfo = kdCompanyService.queryAll();
        return Response.success(new PageUtil<MallKdCompany>(pageinfo));
    }

    @ApiOperation("新增快递公司")
    @PostMapping("/add")
    public Response add(KdCompanyAddVO companyAddVO) {
        MallKdCompany mallKdCompany = new MallKdCompany();
        BeanUtils.copyProperties(companyAddVO, mallKdCompany);
        try {
            Boolean flag = kdCompanyService.save(mallKdCompany);
            return Response.success(flag);
        } catch (RuntimeException ex) {
            return Response.error(ex.getMessage());
        }

    }

}
